#include <iostream>
#include <signal.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>

using namespace std; 

int main(){
	
	cout << getpid() << endl;
	int pid; 
	int pid1; 
	if((pid = fork()) < 0){
		cout << " error " << endl;
	}
	else if(pid == 0){
		//child
		sleep(1); 
		cout << "over child 1\n" ; 
	}
	else{
		if((pid1 = fork() ) < 0){
			cout << "error fork 2 " << endl;
		}
		else if(pid1 == 0){
			while(1){
				if(getppid() == 1){
					cout << " I am guer"  << getpid()  << endl;
					exit(0);
				}else{
					cout << " I hava a family \n" << getppid(); 

				}
				sleep(1);
			}
		}
		int status; 
		wait(&status); 
		cout << "over \n" ; }
}

